﻿
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XYTXL.API;
using XYTXL.AppCode;
using XYTXL.Data;

namespace XYTXL.Web.View.UCMangForm
{
    public partial class XYGL : FormUControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            
            }
        }


        public override void initALLForm(string strFormCode)
        {
            new CommonHelp.BindData().BindNj(ddNj);
            new CommonHelp.BindData().BindYx(ddYx);
        }


        /// <summary>
        /// 重写父类的保存数据方法
        /// </summary>
        /// <param name="intFormID">数据ID</param>
        /// <param name="strActionType">操作类型("ADD":"添加","UPDATE":"修改")</param>
        /// <returns></returns>
        public override bool SaveForm(int intFormID, string strActionType, int pid)
        {
            //执行 父类的方法
            base.SaveForm(intFormID, strActionType);

            //保存数据
            xy_xsxx Model = new xy_xsxxB().GetEntity(d => d.ID == intFormID);
            Model.xm = txtXm.Text;
            Model.xh = txtXh.Text;
            Model.NJ = int.Parse(ddNj.SelectedValue.ToString());
            Model.xbmc = ddYx.SelectedItem.Text;
            Model.xbdm = ddYx.SelectedValue;
            Model.zydm = ddZy.SelectedValue;
            Model.zymc = ddZy.SelectedItem.Text;
            Model.bj = conBJ.SelectedItem.Text;
            Model.bh = conBJ.SelectedValue ;
            Model.xb = ddlXB.SelectedValue;
            Model.pas = conMM.Text;
            Model.now_tel = conPhone.Text;
            Model.grade = ddlJB.SelectedValue;
            Model.type = ddlLX.SelectedValue;
            Model.nzcname = conYHM.Text;
            Model.xxjl = hidxxjl.Value;
            Model.gzjl = hidgzjl.Value;
            //JObject tt = (JObject)JsonConvert.DeserializeObject(strXXJL);

            return new xy_xsxxB().Update(Model);
        }




        public override void initMangerForm(int intFormID, string strActionType)
        {
            base.initMangerForm(intFormID, strActionType);
            xy_xsxx Model = new xy_xsxxB().GetEntity(d => d.ID == intFormID);
            txtXm.Text = Model.xm;
            txtXh.Text = Model.xh;

            conMM.Text = Model.pas;
            conPhone.Text = Model.now_tel;
            ddlJB.SelectedValue = Model.grade;
            ddlLX.SelectedValue = Model.type;
            ddNj.SelectedValue = Model.NJ.ToString();
            ddYx.SelectedValue = Model.xbdm.ToString();
            ddlXB.SelectedValue = Model.xb;
            new CommonHelp.BindData().BindZY(ddZy, ddNj.SelectedValue, ddYx.SelectedValue);
            ddZy.SelectedValue = Model.zydm.ToString();

            new CommonHelp.BindData().BindBJ(conBJ, ddNj.SelectedValue, ddYx.SelectedValue, ddZy.SelectedValue);
            conBJ.SelectedValue = Model.bh;

            hidxxjl.Value = Model.xxjl;
            hidgzjl.Value = Model.gzjl;
            conYHM.Text = Model.nzcname;

            //ddZy.SelectedItem.Text = Model.zymc.ToString();

            //ddlIsShow.SelectedValue = Model.IsShow.ToString();

            //JH_MH_LMGL lm = new JH_MH_LMGLB().GetEntity(d => d.ID == Model.Type);
            //new CommonHelp.BindData().BindLM(ddlLM1);
            //ddlLM1.SelectedValue = lm.TopID.ToString();
            //new CommonHelp.BindData().BindLM(ddlLM2, ddlLM1.SelectedValue);
            //ddlLM2.SelectedValue = Model.Type.ToString();
        }

        protected void ddNj_SelectedIndexChanged(object sender, EventArgs e)
        {
            new CommonHelp.BindData().BindZY(ddZy,ddNj.SelectedValue,ddYx.SelectedValue);

        }
        protected void ddYx_SelectedIndexChanged(object sender, EventArgs e)
        {
            new CommonHelp.BindData().BindZY(ddZy, ddNj.SelectedValue, ddYx.SelectedValue);

        }
        protected void ddZY_SelectedIndexChanged(object sender, EventArgs e)
        {
            new CommonHelp.BindData().BindBJ(conBJ, ddNj.SelectedValue, ddYx.SelectedValue, ddZy.SelectedValue);

        }

        
    }
}